<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of VMT_MBBathy</title>
  <meta name="keywords" content="VMT_MBBathy">
  <meta name="description" content="Computes the multibeam bathymetry from the four beams of the ADCP">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- menu.html VMT_4.0_dev -->
<h1>VMT_MBBathy
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Computes the multibeam bathymetry from the four beams of the ADCP</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [A] = VMT_MBBathy(z,A,savefile,beamAng,magVar,wsedata,saveaux) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Computes the multibeam bathymetry from the four beams of the ADCP
 using a script by D.Mueller (USGS). Beam depths are computed for each
 transect prior to any averaging or mapping.

 Added the ability to export timestamps, pitch, roll, and heading
 (2/1/10)

 Added an identifier for each individual transect to the csv output
(FEL, 6/14/12)

 V3 Adds capability to handle timeseries of WSE, PRJ 8-7-12

 P.R. Jackson, USGS, 8-7-12</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="VMT.html" class="code" title="function varargout = VMT(varargin)">VMT</a>	--- THE VELOCITY MAPPING TOOLBOX ---</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [A] = VMT_MBBathy(z,A,savefile,beamAng,magVar,wsedata,saveaux)</a>
0002 <span class="comment">% Computes the multibeam bathymetry from the four beams of the ADCP</span>
0003 <span class="comment">% using a script by D.Mueller (USGS). Beam depths are computed for each</span>
0004 <span class="comment">% transect prior to any averaging or mapping.</span>
0005 <span class="comment">%</span>
0006 <span class="comment">% Added the ability to export timestamps, pitch, roll, and heading</span>
0007 <span class="comment">% (2/1/10)</span>
0008 <span class="comment">%</span>
0009 <span class="comment">% Added an identifier for each individual transect to the csv output</span>
0010 <span class="comment">%(FEL, 6/14/12)</span>
0011 <span class="comment">%</span>
0012 <span class="comment">% V3 Adds capability to handle timeseries of WSE, PRJ 8-7-12</span>
0013 <span class="comment">%</span>
0014 <span class="comment">% P.R. Jackson, USGS, 8-7-12</span>
0015 
0016 <span class="comment">%% Start</span>
0017 <span class="keyword">try</span>
0018     <span class="comment">%disp('Computing corrected beam depths')</span>
0019     <span class="keyword">if</span> isstruct(wsedata)
0020         <span class="keyword">if</span> length(wsedata.elev) == 1
0021             <span class="comment">%disp('WSE is a constant value')</span>
0022             wsefiletype = 0;
0023         <span class="keyword">else</span>
0024             <span class="comment">%disp('WSE is a timeseries')</span>
0025             wsefiletype = 1;
0026         <span class="keyword">end</span>
0027     <span class="keyword">else</span>
0028         <span class="comment">%disp('WSE is a constant value')</span>
0029         wsedata.elev = wsedata;
0030         wsefiletype = 0;
0031     <span class="keyword">end</span>
0032     
0033     <span class="comment">%% Step through each transect in the given set</span>
0034     <span class="comment">%figure(1); clf</span>
0035     <span class="keyword">for</span> zi = 1 : z
0036         
0037         <span class="comment">% Work on the WSE if a vector</span>
0038         <span class="comment">%WSE vector must have a value for each ensemble, so interpolate given</span>
0039         <span class="comment">%values to ensemble times</span>
0040         
0041         <span class="keyword">if</span> wsefiletype  <span class="comment">%only process as vector if loaded file rather than single value</span>
0042             <span class="comment">%Build an ensemble time vector</span>
0043             enstime = datenum([A(zi).Sup.year+2000 A(zi).Sup.month A(zi).Sup.day<span class="keyword">...</span>
0044                 A(zi).Sup.hour A(zi).Sup.minute (A(zi).Sup.second+A(zi).Sup.sec100./100)]);
0045             <span class="comment">%Had to add 2000 to year--will not work for years &lt; 2000</span>
0046             <span class="comment">%Check the times (for debugging)</span>
0047             <span class="keyword">if</span> 0
0048                 obs_start = datestr(wsedata.obstime(1))
0049                 obs_end = datestr(wsedata.obstime(end))
0050                 
0051                 ens_start = datestr(enstime(1))
0052                 ens_end = datestr(enstime(end))
0053             <span class="keyword">end</span>
0054             
0055             <span class="comment">% Interpolate the WSE values to the ENS times</span>
0056             wse = interp1(wsedata.obstime,wsedata.elev,enstime);
0057             <span class="comment">% Plot for debugging</span>
0058             <span class="keyword">if</span> 0
0059                 figure(1); hold on
0060                 plot(enstime,wse,<span class="string">'k-'</span>)
0061                 datetick(<span class="string">'x'</span>,13)
0062                 ylabel(<span class="string">'WSE, in meters'</span>)
0063             <span class="keyword">end</span>
0064         <span class="keyword">else</span>
0065             wse = wsedata.elev; <span class="comment">%Single value</span>
0066         <span class="keyword">end</span>
0067         
0068         <span class="comment">% Compute position and elevation of each beam depth</span>
0069         [exyz] = depthxyz(A(zi).Nav.depth,A(zi).Sup.draft_cm,<span class="keyword">...</span>
0070             A(zi).Sensor.pitch_deg,A(zi).Sensor.roll_deg,<span class="keyword">...</span><span class="comment">.</span>
0071             A(zi).Sensor.heading_deg,beamAng,<span class="keyword">...</span>
0072             <span class="string">'m'</span>,A(zi).Comp.xUTMraw,A(zi).Comp.yUTMraw,wse,A(zi).Sup.ensNo);  <span class="comment">%magVar,removed 4-8-10</span>
0073         
0074         <span class="comment">%Build the auxillary data matrix</span>
0075         <span class="keyword">if</span> saveaux
0076             auxmat = [A(zi).Sup.year+2000 A(zi).Sup.month A(zi).Sup.day<span class="keyword">...</span>
0077                 A(zi).Sup.hour A(zi).Sup.minute (A(zi).Sup.second+A(zi).Sup.sec100./100) <span class="keyword">...</span>
0078                 A(zi).Sensor.heading_deg A(zi).Sensor.pitch_deg A(zi).Sensor.roll_deg <span class="keyword">...</span>
0079                 repmat(zi,size(A(zi).Sup.year))]; <span class="comment">% Added transect #(zi) FLE 6/14/12    %Had to add 2000 to year--will not work for years &lt; 2000</span>
0080             auxmat2 = [];
0081             <span class="keyword">for</span> i = 1:length(A(zi).Sup.ensNo);
0082                 dum = repmat(auxmat(i,:),4,1);
0083                 auxmat2 = cat(1,auxmat2,dum);
0084             <span class="keyword">end</span>
0085             clear auxmat dum enstime wse
0086         <span class="keyword">end</span>
0087         
0088         <span class="comment">% Store results</span>
0089         idxmbb = find(~isnan(exyz(:,4))&amp; ~isnan(exyz(:,2)));
0090         <span class="keyword">if</span> zi==1
0091             zmbb=[exyz(idxmbb,1) exyz(idxmbb,2)<span class="keyword">...</span>
0092                 exyz(idxmbb,3) exyz(idxmbb,4)];
0093             <span class="keyword">if</span> saveaux
0094                 auxmbb = auxmat2(idxmbb,:);
0095             <span class="keyword">end</span>
0096         <span class="keyword">else</span>
0097             zmbb=cat(1,zmbb,[exyz(idxmbb,1)<span class="keyword">...</span>
0098                 exyz(idxmbb,2) exyz(idxmbb,3) exyz(idxmbb,4)]);
0099             <span class="keyword">if</span> saveaux
0100                 auxmbb = cat(1,auxmbb,auxmat2(idxmbb,:));
0101             <span class="keyword">end</span>
0102         <span class="keyword">end</span>
0103         
0104         A(zi).Comp.exyz = exyz(idxmbb,:);
0105         
0106         
0107         clear idxmbb exyz;
0108         <span class="comment">%pack;</span>
0109     <span class="keyword">end</span>
0110     
0111     
0112     <span class="comment">%% Save the data</span>
0113     
0114     <span class="keyword">if</span> 1
0115         <span class="comment">%disp('Exporting multibeam bathymetry')</span>
0116         <span class="comment">%disp([savefile(1:end-4) '_mbxyz.csv'])</span>
0117         outfile = [savefile(1:end-4) <span class="string">'.csv'</span>];
0118         <span class="keyword">if</span> saveaux
0119             outmat = [zmbb auxmbb];
0120             ofid   = fopen(outfile, <span class="string">'wt'</span>);
0121             outcount = fprintf(ofid,<span class="string">'EnsNo,     Easting_WGS84_m,    Northing_WGS84_m,  Elev_m,  Year,  Month,  Day,  Hour,  Minute,  Second,  Heading_deg,  Pitch_deg,  Roll_deg,  Transect\n'</span>); <span class="comment">% Modified to output transect # FLE 6/14/12</span>
0122             outcount = fprintf(ofid,<span class="string">'%6.0f, %14.2f, %14.2f, %8.2f, %4.0f, %2.0f, %2.0f, %2.0f, %2.0f, %2.2f, %3.3f, %3.3f, %3.3f, %3.0f\n'</span>,outmat');
0123             fclose(ofid);
0124         <span class="keyword">else</span>
0125             outmat = zmbb;
0126             ofid   = fopen(outfile, <span class="string">'wt'</span>);
0127             outcount = fprintf(ofid,<span class="string">'EnsNo,     Easting_WGS84_m,    Northing_WGS84_m,  Elev_m\n'</span>);
0128             outcount = fprintf(ofid,<span class="string">'%6.0f, %14.2f, %14.2f, %8.2f\n'</span>,outmat');
0129             fclose(ofid);
0130         <span class="keyword">end</span>
0131         <span class="comment">%dlmwrite([savefile(1:end-4) '_mbxyz.csv'],outmat,'precision',15);</span>
0132     <span class="keyword">end</span>
0133     
0134 <span class="keyword">catch</span> err
0135     erstg = {<span class="string">'An unexpected error occurred during processing. Execution stopped.'</span>};
0136     errordlg(erstg,<span class="string">'VMT Status'</span>,<span class="string">'replace'</span>);
0137     rethrow(err)
0138     <span class="keyword">return</span>
0139 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Thu 21-Mar-2013 09:32:01 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>